package warmachineroster.grapheditor.figure;

import java.net.URL;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.swt.graphics.Image;

import warmachinesystem.provider.WarmachineSystemEditPlugin;

public class SoloRosterElementFigure extends RoundedRectangle {

	private String armyListCode;

	public SoloRosterElementFigure(String name, String armyCode){
		ToolbarLayout layout = new ToolbarLayout(true);
		layout.setStretchMinorAxis(true);
		setLayoutManager(layout);
		setBorder(new MarginBorder(5));
		setForegroundColor(ColorConstants.black);
		setOpaque(true);
		armyListCode = armyCode;
		//aggiungo tre pannelli che rappresentano le colonne della figure
		
		
		RectangleFigure rectangle1 = new RectangleFigure();
		rectangle1.add(getImageFigure());
		
		add(rectangle1);
		
		RectangleFigure rectangle2 = new RectangleFigure();
		rectangle2.add(new Label(name));
		
	}
	
	private ImageFigure getImageFigure() {
		String imgKey = "full/obj32/"+ armyListCode + "_32.png";
		Image img = getImage(imgKey);
		return new ImageFigure(img);
	}
	
	protected Image getImage(String imgKey) {
		URL imgUrl = (URL) getResourceLocator().getImage(imgKey);
		return ExtendedImageRegistry.INSTANCE.getImage(imgUrl);
	}
	
	/**
	 * Return the resource locator for this item provider's resources. <!--
	 * begin-user-doc --> <!-- end-user-doc -->
	 */
	public ResourceLocator getResourceLocator() {
		return WarmachineSystemEditPlugin.INSTANCE;
	
	}
	
}
